﻿using Common;
using Common.MQ;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sample.Controllers
{
    [ApiController]
    [Route("[controller]")]
    [AllowAnonymous]
    public class QueueController : ControllerBase
    {
        private readonly IMQProducer producer;
        public QueueController(IMQProducer producer)
        {
            this.producer = producer;
        }
        [HttpPost]
        public async Task<FuncResult> ProduceAsync(MQMessageStructure data)
        {
            var random = new Random();
            //await producer.ProduceAsync(data, null);
            var msgData = new MessageModel<MQMessageStructure>("topic://zysaz/userprofile", data);
            data.AccountId = Guid.NewGuid().ToString("N");
            data.Balance = random.Next(1000000, 9999999);
            data.Balance /= 100m;
            await MQ.Provider.Producer.ProduceAsync(msgData);
            return FuncResult.Success();
        }
    }
    public static class MQ
    {
        public static IMessageQueueProvider Provider { get; set; }
    }
}
